<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DevKnowledge - Android/Flutter学习</title>
    <style>
        :root {
            --primary-orange: #FF6B6B;
            --primary-blue: #4ECDC4;
            --text-dark: #2D3436;
            --text-medium: #636E72;
            --text-light: #DFE6E9;
            --bg-light: #FFFFFF;
            --bg-dark: #121212;
            --divider: #E0E0E0;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            margin: 0;
            padding: 0;
            background-color: var(--bg-light);
            color: var(--text-dark);
            max-width: 375px;
            margin: 0 auto;
            height: 667px;
            position: relative;
            overflow: hidden;
            box-shadow: 0 0 20px rgba(0,0,0,0.1);
        }

        .dark-mode {
            background-color: var(--bg-dark);
            color: var(--text-light);
        }

        .header {
            padding: 15px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 1px solid var(--divider);
        }

        .title {
            font-weight: 600;
            font-size: 18px;
        }

        .tab-container {
            display: flex;
            border-bottom: 1px solid var(--divider);
        }

        .tab {
            flex: 1;
            text-align: center;
            padding: 15px 0;
            font-weight: 500;
            cursor: pointer;
        }

        .tab.active {
            color: var(--primary-orange);
            border-bottom: 2px solid var(--primary-orange);
        }

        .content {
            height: calc(100% - 110px);
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }

        .knowledge-framework {
            padding: 15px;
        }

        .framework-item {
            margin-bottom: 10px;
        }

        .framework-title {
            display: flex;
            align-items: center;
            font-weight: 500;
            padding: 8px 0;
            cursor: pointer;
        }

        .arrow {
            margin-right: 8px;
            transition: transform 0.2s;
        }

        .arrow.expanded {
            transform: rotate(90deg);
        }

        .sub-items {
            margin-left: 20px;
            display: none;
        }

        .sub-item {
            padding: 6px 0;
            display: flex;
            align-items: center;
        }

        .status-dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            margin-right: 8px;
        }

        .status-dot.unknown {
            background-color: var(--primary-orange);
        }

        .status-dot.known {
            background-color: var(--primary-blue);
        }

        .qa-container {
            display: none;
            padding: 15px;
        }

        .question-card {
            background-color: white;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 15px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .dark-mode .question-card {
            background-color: #1E1E1E;
        }

        .question {
            font-weight: 500;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .answer {
            margin-top: 10px;
            padding-top: 10px;
            border-top: 1px solid var(--divider);
            display: none;
        }

        .actions {
            display: flex;
            justify-content: space-between;
            margin-top: 15px;
        }

        .action-btn {
            padding: 6px 12px;
            border-radius: 4px;
            font-size: 13px;
            cursor: pointer;
            border: none;
            background: none;
            font-weight: 500;
        }

        .favorite {
            color: var(--primary-orange);
        }

        .favorite.active {
            color: gold;
        }

        .known-btn {
            color: var(--primary-blue);
        }

        .bottom-nav {
            position: absolute;
            bottom: 0;
            width: 100%;
            display: flex;
            border-top: 1px solid var(--divider);
            background-color: var(--bg-light);
        }

        .dark-mode .bottom-nav {
            background-color: var(--bg-dark);
        }

        .nav-item {
            flex: 1;
            text-align: center;
            padding: 12px 0;
            cursor: pointer;
        }

        .nav-item.active {
            color: var(--primary-orange);
        }

        /* Low-poly decoration */
        .polygon-decoration {
            position: absolute;
            width: 100px;
            height: 100px;
            opacity: 0.1;
            z-index: -1;
        }

        .polygon-1 {
            top: 50px;
            right: -30px;
            background-color: var(--primary-orange);
            clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
            transform: rotate(45deg);
        }

        .polygon-2 {
            bottom: 100px;
            left: -20px;
            background-color: var(--primary-blue);
            clip-path: polygon(30% 0%, 70% 0%, 100% 100%, 0% 100%);
        }
    </style>
</head>
<body>
<div class="polygon-decoration polygon-1"></div>
<div class="polygon-decoration polygon-2"></div>

<div class="header">
    <div class="title">DevKnowledge</div>
    <div class="action-btn" id="theme-toggle">🌙</div>
</div>

<div class="tab-container">
    <div class="tab active" data-tab="android">Android</div>
    <div class="tab" data-tab="flutter">Flutter</div>
</div>

<div class="content">
    <div class="knowledge-framework" id="android-framework">
        <div class="framework-item">
            <div class="framework-title" onclick="toggleSubItems(this)">
                <span class="arrow">▶</span>
                <span>四大组件</span>
            </div>
            <div class="sub-items">
                <div class="sub-item">
                    <span class="status-dot unknown"></span>
                    <span>Activity</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot known"></span>
                    <span>Service</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot unknown"></span>
                    <span>BroadcastReceiver</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot known"></span>
                    <span>ContentProvider</span>
                </div>
            </div>
        </div>

        <div class="framework-item">
            <div class="framework-title" onclick="toggleSubItems(this)">
                <span class="arrow">▶</span>
                <span>UI系统</span>
            </div>
            <div class="sub-items">
                <div class="sub-item">
                    <span class="status-dot known"></span>
                    <span>View体系</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot unknown"></span>
                    <span>自定义View</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot unknown"></span>
                    <span>动画系统</span>
                </div>
            </div>
        </div>

        <div class="framework-item">
            <div class="framework-title" onclick="toggleSubItems(this)">
                <span class="arrow">▶</span>
                <span>数据存储</span>
            </div>
            <div class="sub-items">
                <div class="sub-item">
                    <span class="status-dot known"></span>
                    <span>SharedPreferences</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot known"></span>
                    <span>SQLite</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot unknown"></span>
                    <span>Room</span>
                </div>
            </div>
        </div>
    </div>

    <div class="knowledge-framework" id="flutter-framework" style="display:none">
        <div class="framework-item">
            <div class="framework-title" onclick="toggleSubItems(this)">
                <span class="arrow">▶</span>
                <span>Widget系统</span>
            </div>
            <div class="sub-items">
                <div class="sub-item">
                    <span class="status-dot known"></span>
                    <span>StatelessWidget</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot unknown"></span>
                    <span>StatefulWidget</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot unknown"></span>
                    <span>InheritedWidget</span>
                </div>
            </div>
        </div>

        <div class="framework-item">
            <div class="framework-title" onclick="toggleSubItems(this)">
                <span class="arrow">▶</span>
                <span>状态管理</span>
            </div>
            <div class="sub-items">
                <div class="sub-item">
                    <span class="status-dot known"></span>
                    <span>setState</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot unknown"></span>
                    <span>Provider</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot unknown"></span>
                    <span>Bloc</span>
                </div>
            </div>
        </div>

        <div class="framework-item">
            <div class="framework-title" onclick="toggleSubItems(this)">
                <span class="arrow">▶</span>
                <span>平台交互</span>
            </div>
            <div class="sub-items">
                <div class="sub-item">
                    <span class="status-dot unknown"></span>
                    <span>MethodChannel</span>
                </div>
                <div class="sub-item">
                    <span class="status-dot unknown"></span>
                    <span>PlatformView</span>
                </div>
            </div>
        </div>
    </div>

    <div class="qa-container" id="android-qa">
        <div class="question-card" onclick="toggleAnswer(this)">
            <div class="question">
                <span>Activity生命周期有哪些？</span>
                <span>▼</span>
            </div>
            <div class="answer">
                <p>onCreate() - 首次创建Activity时调用</p>
                <p>onStart() - Activity即将对用户可见时调用</p>
                <p>onResume() - Activity开始与用户交互时调用</p>
                <p>onPause() - 当Activity失去焦点但仍部分可见时调用</p>
                <p>onStop() - Activity完全不可见时调用</p>
                <p>onDestroy() - Activity被销毁前调用</p>
                <p>onRestart() - Activity从停止状态重新启动时调用</p>
                <div class="actions">
                    <button class="action-btn favorite" onclick="toggleFavorite(event, this)">★ 收藏</button>
                    <button class="action-btn known-btn" onclick="markAsKnown(event, this)">✓ 已掌握</button>
                </div>
            </div>
        </div>

        <div class="question-card" onclick="toggleAnswer(this)">
            <div class="question">
                <span>Intent的作用是什么？</span>
                <span>▼</span>
            </div>
            <div class="answer">
                <p>Intent是Android中用于组件间通信的消息对象，主要作用包括：</p>
                <p>1. 启动Activity: startActivity(intent)</p>
                <p>2. 启动Service: startService(intent)</p>
                <p>3. 发送广播: sendBroadcast(intent)</p>
                <p>4. 在不同组件间传递数据</p>
                <div class="actions">
                    <button class="action-btn favorite active" onclick="toggleFavorite(event, this)">★ 已收藏</button>
                    <button class="action-btn known-btn" onclick="markAsKnown(event, this)">✓ 已掌握</button>
                </div>
            </div>
        </div>
    </div>

    <div class="qa-container" id="flutter-qa" style="display:none">
        <div class="question-card" onclick="toggleAnswer(this)">
            <div class="question">
                <span>什么是BuildContext？</span>
                <span>▼</span>
            </div>
            <div class="answer">
                <p>BuildContext是Flutter中表示Widget在树中位置的句柄，主要作用：</p>
                <p>1. 用于查找父级Widget或主题等资源</p>
                <p>2. 在Widget树中向上查找InheritedWidget</p>
                <p>3. 每个Widget都有自己对应的BuildContext</p>
                <p>4. 通过context可以获取媒体查询、主题等全局信息</p>
                <div class="actions">
                    <button class="action-btn favorite" onclick="toggleFavorite(event, this)">★ 收藏</button>
                    <button class="action-btn known-btn" onclick="markAsKnown(event, this)">✓ 已掌握</button>
                </div>
            </div>
        </div>

        <div class="question-card" onclick="toggleAnswer(this)">
            <div class="question">
                <span>StatelessWidget和StatefulWidget的区别？</span>
                <span>▼</span>
            </div>
            <div class="answer">
                <p>1. StatelessWidget是不可变的，一旦创建就不能改变</p>
                <p>2. StatefulWidget可以维护可变状态，通过setState()触发重建</p>
                <p>3. StatelessWidget性能更好，应优先使用</p>
                <p>4. StatefulWidget由两部分组成：Widget和State对象</p>
                <div class="actions">
                    <button class="action-btn favorite" onclick="toggleFavorite(event, this)">★ 收藏</button>
                    <button class="action-btn known-btn" onclick="markAsKnown(event, this)">✓ 已掌握</button>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="bottom-nav">
    <div class="nav-item active" data-view="framework">知识框架</div>
    <div class="nav-item" data-view="qa">问答练习</div>
    <div class="nav-item" data-view="favorites">我的收藏</div>
</div>

<script>
    // 切换主题
    const themeToggle = document.getElementById('theme-toggle');
    themeToggle.addEventListener('click', () => {
        document.body.classList.toggle('dark-mode');
        themeToggle.textContent = document.body.classList.contains('dark-mode') ? '☀️' : '🌙';
    });

    // 切换标签页
    const tabs = document.querySelectorAll('.tab');
    tabs.forEach(tab => {
        tab.addEventListener('click', () => {
            tabs.forEach(t => t.classList.remove('active'));
            tab.classList.add('active');

            const tabName = tab.getAttribute('data-tab');
            document.getElementById('android-framework').style.display = 'none';
            document.getElementById('flutter-framework').style.display = 'none';
            document.getElementById('android-qa').style.display = 'none';
            document.getElementById('flutter-qa').style.display = 'none';

            if (tabName === 'android') {
                const currentView = document.querySelector('.nav-item.active').getAttribute('data-view');
                if (currentView === 'framework') {
                    document.getElementById('android-framework').style.display = 'block';
                } else {
                    document.getElementById('android-qa').style.display = 'block';
                }
            } else {
                const currentView = document.querySelector('.nav-item.active').getAttribute('data-view');
                if (currentView === 'framework') {
                    document.getElementById('flutter-framework').style.display = 'block';
                } else {
                    document.getElementById('flutter-qa').style.display = 'block';
                }
            }
        });
    });

    // 切换底部导航
    const navItems = document.querySelectorAll('.nav-item');
    navItems.forEach(item => {
        item.addEventListener('click', () => {
            navItems.forEach(i => i.classList.remove('active'));
            item.classList.add('active');

            const view = item.getAttribute('data-view');
            const currentTab = document.querySelector('.tab.active').getAttribute('data-tab');

            document.getElementById('android-framework').style.display = 'none';
            document.getElementById('flutter-framework').style.display = 'none';
            document.getElementById('android-qa').style.display = 'none';
            document.getElementById('flutter-qa').style.display = 'none';

            if (view === 'framework') {
                if (currentTab === 'android') {
                    document.getElementById('android-framework').style.display = 'block';
                } else {
                    document.getElementById('flutter-framework').style.display = 'block';
                }
            } else if (view === 'qa') {
                if (currentTab === 'android') {
                    document.getElementById('android-qa').style.display = 'block';
                } else {
                    document.getElementById('flutter-qa').style.display = 'block';
                }
            } else if (view === 'favorites') {
                alert('收藏功能将在完整版中实现');
            }
        });
    });

    // 知识框架子项展开/收起
    function toggleSubItems(element) {
        const arrow = element.querySelector('.arrow');
        const subItems = element.nextElementSibling;

        arrow.classList.toggle('expanded');

        if (subItems.style.display === 'block') {
            subItems.style.display = 'none';
        } else {
            subItems.style.display = 'block';
        }
    }

    // 问题答案展开/收起
    function toggleAnswer(card) {
        const answer = card.querySelector('.answer');
        const arrow = card.querySelector('.question span:last-child');

        if (answer.style.display === 'block') {
            answer.style.display = 'none';
            arrow.textContent = '▼';
        } else {
            answer.style.display = 'block';
            arrow.textContent = '▲';
        }
    }

    // 收藏问题
    function toggleFavorite(event, button) {
        event.stopPropagation();
        button.classList.toggle('active');
        button.textContent = button.classList.contains('active') ? '★ 已收藏' : '★ 收藏';
    }

    // 标记为已掌握
    function markAsKnown(event, button) {
        event.stopPropagation();
        const card = button.closest('.question-card');
        const questionText = card.querySelector('.question span:first-child').textContent;
        alert(`已标记"${questionText}"为已掌握`);
    }
</script>
</body>
</html>